package net.cruciblesoftware.embers;

import android.content.res.Resources;
import android.util.Log;
import java.lang.reflect.Field;

class Settings {
    private static Resources resources;
    private static Field[] intFields;
    private static boolean loaded = false;

    public static void load(Resources res) {
        if(loaded)
            return;
        Log.i("SETNG", "loading settings...");
        resources = res;
        Class<R.integer> resInt = R.integer.class;
        intFields = resInt.getDeclaredFields();
    }


    public static int getInt(String setting) {
        int resId = 0;
        try {
            for(Field f : intFields) {
                if(f.getName().equals(setting)) {
                    resId = f.getInt(null);
                    break;
                }
            }
        } catch(IllegalAccessException e) {
            Log.w("SETNG", "could not access resource: " + e.toString());
        } 
        return resources.getInteger(resId);
    }


    public static float getPercent(String setting) {
        int val = getInt(setting);
        return (val / 100.0f);
    }


    public static float getScaled(String setting) {
        float scaledVal = getInt(setting);
        while(scaledVal > 1.0f || scaledVal < -1.0f)
            scaledVal /= 10.0f;
        return scaledVal;
    }
}
